<template>
<!-- 详情--关联销售单 -->
  <div>
    <zm-form :model="searchForm" ref="searchForm" inline>
      <zm-form-item prop="orderNo">
        <zm-input
          v-model="searchForm.orderNo"
          placeholder="输入销售单号查询"
          class="w200"
        ></zm-input>
      </zm-form-item>
      <zm-form-item prop="saleOrderNo">
        <zm-input
          v-model="searchForm.saleOrderNo"
          placeholder="输入方案关联销售单号"
          class="w200"
        ></zm-input>
      </zm-form-item>
      <zm-form-item>
        <zm-button @click="onReset" t="reset"></zm-button>
        <zm-button @click="onSearch" t="search"></zm-button>
        <zm-button type="success" @click="isVisibleDialog = true">
          添加
        </zm-button>
        <zm-export :api="exportOrder" type="warning" :params="exportOrderForm" size="mini">
          导出
        </zm-export>
      </zm-form-item>
    </zm-form>
    <zm-table-data
      :data="tableParams.data"
      :columns="columns"
      :fetch="loadList"
      :table-params="tableParams"
      :show-page="true"
    >
    </zm-table-data>
    <add-dialog
      v-if="isVisibleDialog"
      v-model="isVisibleDialog"
      @refresh="onSearch"
      :id="id"
    ></add-dialog>
  </div>
</template>

<script>
import tableMixin from '@/mixins/zmTableMixin'
import { columns } from '../const'
import {
  getBindOrderList,
  saleOrderUnbind,
  exportOrder
} from '@/api/src/sendCouponSet'
import AddDialog from './AddDialog.vue'
export default {
  name: 'AssociatedSalesOrder',
  components: { AddDialog },
  mixins: [tableMixin],
  props: {
    id: {
      type: String,
      required: true
    },
    obj: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      exportOrder,
      searchForm: {
        orderNo: '',
        saleOrderNo: '' // 方案关联销售单号
      },
      isVisibleDialog: false
    }
  },
  computed: {
    columns () {
      return columns(this)
    },
    exportOrderForm () {
      return {
        ...this.searchForm,
        programId: this.id
      }
    }
  },
  watch: {},
  created () {},
  methods: {
    async loadList () {
      const _res = await getBindOrderList(
        this.assignQuery({ ...this.searchForm, programId: this.id })
      )
      this.initialTableData(_res.list, _res.count)
    },
    async isBind (row) {
      await saleOrderUnbind({ orderNo: row.orderNo, programId: this.id })
      this.loadList()
    }
  }
}
</script>

<style scoped lang="scss"></style>
